﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.UI.WebControls;
using MvcApplication1.Controllers.FilterExtend;

//using PagedList;
using MvcApplication1.Models;
using myframework._99_热身.time._2011_10_24_scm;

namespace MvcApplication1.Controllers
{
    public class person
    {
        public string id { get; set; }

        public string name { get; set; }
    }

    public class tt12
    {
        public string id { get; set; }

        public string name { get; set; }
    }

    public class testController : Controller
    {
        public ActionResult t46()
        {
            //System.Threading.Thread.Sleep(5000);
            HttpContext.Response.Write("2");

            return View();
        }

        public ActionResult t45()
        {
            //System.Threading.Thread.Sleep(5000);

            Session["name"] = "zr";
            return View();
        }

        public ActionResult t44()
        {
            ViewData["msg"] = "time";
            return View();
        }

        public ActionResult t43()
        {
            string data = "";
            HttpCookie cookie = System.Web.HttpContext.Current.Request.Cookies["zr"];
            if (cookie != null)
            {
                data = System.Web.HttpContext.Current.Server.UrlDecode(cookie.Value);
            }
            ViewData["msg"] = data;
            return View();
        }

        public ActionResult t42()
        {
            HttpCookie cookie = new HttpCookie("zr");
            //if (System.Web.HttpContext.Current.)
            cookie.Value = System.Web.HttpContext.Current.Server.UrlEncode("hello word");
            System.Web.HttpContext.Current.Response.Cookies.Add(cookie);

            ViewData["msg"] = "已经添加cookie";
            return View();
        }

        [HttpPost]
        public ActionResult t41(FormCollection values)
        {
            string s = values["zr"];
            ViewData["zr"] = s;
            return View();
        }

        public ActionResult t41()
        {
            return View();
        }

        public ActionResult t40()
        {
            return View();
        }

        [Class1]
        public ActionResult t39()
        {
            return View();
        }

        public ActionResult t38()
        {
            person p = new person() { id = "1", name = "zr" };
            return View(p);
        }

        [time.LoginFilter]
        public ActionResult t37()
        {
            ViewData["a"] = null;

            return View();
        }

        public ActionResult t36()
        {
            return View();
        }

        public ActionResult t33()
        {
            return View();
        }

        public ActionResult t32()
        {
            return View();
        }

        public ActionResult t311(MvcApplication1.Controllers.person p)
        {
            return PartialView(p);
        }

        public ActionResult t31()
        {
            List<SelectListItem> ls = new List<SelectListItem>();
            SelectListItem s1 = new SelectListItem();
            s1.Text = "奥特曼";
            s1.Value = "奥特曼";

            SelectListItem s2 = new SelectListItem();
            s2.Text = "阿拉蕾";
            s2.Value = "阿拉蕾";

            ls.Add(s1);
            ls.Add(s2);

            ViewData["name"] = ls;

            //person p = new person() { id = "1", name = "zr" };
            //return View(p);
            return View();
        }

        //public ActionResult t22(int? page)
        //{
        //    //var listPaged = GetPagedNames(page);
        //    //if (listPaged == null)
        //    //    return HttpNotFound();

        //    //// pass the paged list to the view and render
        //    //ViewBag.Names = listPaged;
        //    //return View();

        //}

        private static List<string> GetStuffFromDatabase()
        {
            List<string> ie = new List<string>();
            ie.Add("1");
            ie.Add("2");
            ie.Add("3");
            ie.Add("4");
            ie.Add("5");

            ie.Add("6");
            ie.Add("7");
            ie.Add("8");
            return ie;
        }

        //private IPagedList<string> GetPagedNames(int? page)
        //{
        //    // return a 404 if user browses to before the first page
        //    if (page.HasValue && page < 1)
        //        return null;

        //    // retrieve list from database/whereverand
        //    var listUnpaged = GetStuffFromDatabase();

        //    // page the list
        //    const int pageSize = 2;
        //    var listPaged = listUnpaged.ToPagedList(page.HasValue ? page.Value - 1 : 0, pageSize);

        //    IEnumerable<string> s = null;
        //    //s.t

        //    // return a 404 if user browses to pages beyond last page. special case first page if no items exist
        //    if (listPaged.PageNumber != 1 && page.HasValue && page > listPaged.PageCount)
        //        return null;

        //    return listPaged;
        //}

        public ActionResult t21()
        {
            DataClasses1DataContext dc = new DataClasses1DataContext();
            return View(dc.Clothes.Take(100).ToList());
        }

        public ActionResult t20(string id)
        {
            List<person> lp = new List<person>();
            person p = new person();
            p.id = "1";
            p.name = "zr";

            person p2 = new person();
            p2.id = "2";
            p2.name = "rr";

            lp.Add(p);
            lp.Add(p2);
            return Json(lp, JsonRequestBehavior.AllowGet);
        }

        public ActionResult t19()
        {
            List<ListItem> list = new List<ListItem>() {
                new ListItem() { Value = "1", Text = "VA" },
                new ListItem() { Value = "2", Text = "MD" },
                new ListItem() { Value = "3", Text = "DC" }      };

            return Json(list, JsonRequestBehavior.AllowGet);
        }

        //
        // GET: /test/
        public ActionResult t181()
        {
            return Content("22");
        }

        public ActionResult t18()
        {
            return View();
        }

        public ActionResult t171(MvcApplication1.Controllers.person p)
        {
            return PartialView(p);
        }

        public ActionResult t17()
        {
            List<SelectListItem> ls = new List<SelectListItem>();
            SelectListItem s1 = new SelectListItem();
            s1.Text = "奥特曼";
            s1.Value = "奥特曼";

            SelectListItem s2 = new SelectListItem();
            s2.Text = "阿拉蕾";
            s2.Value = "阿拉蕾";

            ls.Add(s1);
            ls.Add(s2);

            ViewData["name"] = ls;

            person p = new person() { id = "1", name = "zr" };
            return View(p);
        }

        public string UpdateForm(string textBox1)
        {
            if (textBox1 != "Enter text")
            {
                return "You entered: \"" + textBox1.ToString() + "\" at " +
                    DateTime.Now.ToLongTimeString();
            }

            return String.Empty;
        }

        public ActionResult t16()
        {
            return View();
        }

        public ActionResult Details(string id)
        {
            //var customer = "33443";

            //return PartialView("Details1", customer);

            return Content("11");
        }

        public ActionResult t15()
        {
            return Content("15");
        }

        public ActionResult t12()
        {
            //ViewData["a"] = "a";
            tt12 t = new tt12() { id = "1", name = "z" };
            return View(t);
        }

        public ActionResult t11()
        {
            return PartialView();
        }

        public ActionResult t10()
        {
            return View();
        }

        public ActionResult t9()
        {
            SelectListItem si = new SelectListItem();
            si.Text = "1";
            si.Value = "1";
            si.Selected = true;

            SelectListItem si2 = new SelectListItem();
            si2.Text = "2";
            si2.Value = "2";

            List<SelectListItem> countList = new List<SelectListItem>();

            countList.Add(si2);
            countList.Add(si);

            ViewData["select"] = countList;

            return View();
        }

        public string GetStatus()
        {
            //string s = "<Script language='javascript'>" + "alert('" + "11" + "......')" + "</script>";
            //HttpContext.Response.Write(s);

            return "Status OK at " + DateTime.Now.ToLongTimeString();

            //return View();
        }

        public string GetStatus1()
        {
            return "Status OK at " + DateTime.Now.ToLongTimeString();
        }

        public ActionResult t8()
        {
            return View();
        }

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult t1()
        {
            return View();
        }

        public ActionResult t2()
        {
            return View();
        }

        public ActionResult t3()
        {
            return View();
        }

        public ActionResult t4()
        {
            return View();
        }

        [HttpPost]
        public ActionResult t4(FormCollection values)
        {
            ViewBag.message = values["a"];
            return View();
        }

        public ActionResult t5()
        {
            t1Models t1 = new t1Models() { a = "1", b = "2" };
            return View(t1);
        }

        public ActionResult WebForm1()
        {
            return View();
        }

        public ActionResult t6()
        {
            int i = 0;
            if (i == 0 && i++ == 0)
            {
                int j = 0;
            }

            return View();
        }

        public ActionResult t7()
        {
            //FileDownload("http://js.vanclimg.com/js.ashx");
            return View();
        }

        ///   <summary>
        ///   文件下载
        ///   </summary>
        ///   <param   name= "FullFileName "> </param>
        //private void FileDownload(string FullFileName)
        //{
        //    FileInfo DownloadFile = new FileInfo(FullFileName);
        //    Response.Clear();
        //    Response.ClearHeaders();
        //    Response.Buffer = false;
        //    Response.ContentType = "application/octet-stream ";
        //    Response.AppendHeader("Content-Disposition ", "attachment;filename= " + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
        //    Response.AppendHeader("Content-Length ", DownloadFile.Length.ToString());
        //    Response.WriteFile(DownloadFile.FullName);
        //    Response.Flush();
        //    Response.End();
        //}
    }
}